package com.yl.rabbitmq.day04;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.yl.rabbitmq.utils.RabbitMQUtil;

import java.util.Scanner;

/**
 * @author yangl
 */
public class Producer04 {
    public static final String TASK_QUEUE_NAME = "durable_ack_name";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtil.getChannel();
        /**
         * 持久化
         * 创建队列，要求队列持久化
         */
        channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            String message = scanner.next();
            /**
             * 设置生产者发送消息为持久化消息，要求保存在磁盘上，默认是保存在内存中
             * 发送消息要求消息持久化
             */
            channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes("UTF-8"));
            System.out.println("生产者发出消息：" + message);
        }
    }
}
